home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group97b.txt
/
000108_icon-group-sender _Thu Oct 30 13:21:36 1997.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
6KB
Return-Path: <icon-group-sender>
Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
by baskerville.CS.Arizona.EDU (8.8.7/8.8.7) with SMTP id NAA21178
for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Thu, 30 Oct 1997 13:21:35 -0700 (MST)
Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
id AA29172; Thu, 30 Oct 1997 13:21:35 -0700
From: gep2@computek.net
Date: Thu, 30 Oct 1997 12:53:03 -0600
Message-Id: <199710301853.MAA25014@axp.cmpu.net>
Mime-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Subject: problem with data type in program
To: icon-group@optima.CS.Arizona.EDU
X-Mailer: SPRY Mail Version: 04.00.06.17
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
>The problem is this. I am getting error messages saying that the main
procedure expects a table does not get one from the procedure it
invokes--namely, scantext(). But it looks to me as if the value returned
by scantext() should be a table. What am I doing wrong?
>Thanks in advance for any help.
The most basic debugging technique for a situation like this is to make sure
that the program is ACTUALLY running the way you EXPECTED it to... that data
values are as you expected, that transfers of control are taking place the way
you wanted them to, etc. etc. And it helps if, when writing a program, you can
design in features to facilitate the initial debugging... and such that they can
be turned off or removed (ideally, progressively) after parts or all of the
program are working. And part of designing in debugging output is knowing where
you should and shouldn't put it, so that you get useful output without drowning
in it. :-)
Let me take your program and show you, for example, what kind of debugging
output I'm talking about (and note that there is no one way to do stuff like
this... you might want more or less... or even done differently... but at least
putting stuff like the following in, and STUDYING WHAT OUTPUT the program then
produces, will help you to understand what your program REALLY does (and,
especially for beginning programmers but sometimes even for us experienced ones,
programs do NOT always follow what my CS professor used to call "The Principle
of Least Astonishment".... :-)
I will not mark quotes during the program text, but will indicate my additions
by using a ">>>>>>" at the beginning of the example debugging lines I've added.
############################################################################
#
# File: tabulate_AO_person.icn
# Subject: Program to tabulate person of A and O
# Author: Stuart P. Robinson
# Date: 14 October, 1997
#
############################################################################
#
# This program was written to calculate what proportion of A's and O's
# are 1st, 2nd, or 3rd person. Unlike previous version, it does NOT give
# percentages--just raw numbers. The 7 logical possibilities it counts are:
#
# 1. 1-2 first_on_second
# 2. 1-3 first_on_third
# 3. 2-1 second_on_first
# 4. 2-3 second_on_third
# 5. 3-1 third_on_first
# 6. 3-2 third_on_second
# 7. 3-3 third_on_third
#
############################################################################
procedure main()
>>>>>> write("procedure main starting")
output := sort( scan_text(), 1 )
>>>>>> write("size of output after sorting is ",*output)
write( "Person Config." || "/t" || "No." )
every x := key( output ) do
write( x || "\t" || output[x] )
>>>>>> write("procedure main is finished")
end
procedure scan_text( )
value_table := table( 0 )
>>>>>> write("scan_text starting")
while line := read()
do
{
>>>>>> write("processing line: '",line,"'")
line ?
{
value_table[ search_line() ] +:= 1
}
}
>>>>>> write("scan_text is returning a value of type ",type(value_table))
return value_table
end
procedure search_line( )
>>>>>> write("search_line starting")
chars := &letters++&digits++'{`'
subject := 0
object := 0
if find( "{Q" ) then
while tab( upto( chars ) ) do
{
word := tab( many( chars ) )
>>>>>> write(" word found: '",word,"'")
word ?
{
if tab( find( "{" ) ) then
word := tab( 0 )
>>>>>> write(" case statement test being started with word: '",word,"'")
case word of
{
"{A1" : subject := 1
"{A2" : subject := 2
"{A" : subject := 3
"{O1" : object := 1
"{O2" : object := 2
"{O" : object := 3
}
}
}
>>>>>> write(" after case statement test, subject=",subject," object=",object)
if subject == 1 then
if object == 2 then type := "first on second"
else if object == 3 then type := "first on third"
if subject == 2 then
if object == 1 then type := "second on first"
else if object == 3 then type := "second on third"
if subject == 3 then
if object == 1 then type := "third on first"
else if object == 2 then type := "third on second"
else if object == 3 then type := "third on third"
>>>>>> write("search_line is returning '",type,"'")
return type
end
Running the program with that debugging output, and STUDYING THE RESULT, will
help you to understand how the program you've written is ACTUALLY working, and
help you to see where it's not ACTUALLY working the way you intended for it to.
Gordon Peterson
http://www.computek.net/public/gep2/
Support the Anti-SPAM Amendment! Join at http://www.cauce.org/